package org.sirmupadbapi.persistencia;

import java.io.Serializable;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.sirmupadbapi.beans.Regimen;
import org.sirmupadbapi.beans.Regimencomercios;
import org.sirmupadbapi.controller.RegimenController;
import org.sirmupadbapi.generales.DataGManager;


/**
*
* @author
*/

public class RegimencomerciosPersistencia implements Serializable {
private static final long serialVersionUID = 1L;
public static Exception excepcion;
public static boolean esMensaje = false;
public static Connection con = null;
public static java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/sirmupadbapi/properties/mensajes");
static DataGManager dataGManager;
static List<Regimencomercios> list;

public RegimencomerciosPersistencia(){
         esMensaje =false;
}


/**
*
* insert()
*/

public static boolean insert (Regimencomercios regimencomercios ) {
  excepcion = null;
  try {
      esMensaje =false;
   
Regimen regimen = new Regimen();
Regimen regimen2 = new Regimen();
RegimenController regimenController = new RegimenController();
   
    regimen.setIdregimen(regimencomercios.getIDREGIMEN());
   
      if(!regimenController.exists(regimen)){
            excepcion=new Exception(bundle.getString("msg.nofoundrecordcodetable") + "regimen" );
           esMensaje = true;
           return false;
      }

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pinsert = null;
      String sql = "insert into regimencomercios(IDCOMERCIO,IDREGIMEN,VALOR,PERIODOPAGO,MESPAGO,FECHAINSCRIPCION,IDUSUARIO,FECHA,ACTIVO,IDMUNICIPIO)  values(?,?,?,?,?,?,?,?,?,?)";
      pinsert = con.prepareStatement(sql);
              pinsert.setString(1,regimencomercios.getIDCOMERCIO());
        pinsert.setString(2,regimencomercios.getIDREGIMEN());
        pinsert.setDouble(3,regimencomercios.getVALOR());
        pinsert.setString(4,regimencomercios.getPERIODOPAGO());
        pinsert.setString(5,regimencomercios.getMESPAGO());
        pinsert.setDate(6,regimencomercios.getFECHAINSCRIPCION());
        pinsert.setString(7,regimencomercios.getIDUSUARIO());
        pinsert.setDate(8,regimencomercios.getFECHA());
        pinsert.setString(9,regimencomercios.getACTIVO());
        pinsert.setString(10,regimencomercios.getIDMUNICIPIO());
      int filas= pinsert.executeUpdate();
      pinsert.close();
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
 }


/**
*
* update()
*/

public static boolean update(Regimencomercios regimencomercios ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update regimencomercios set  IDCOMERCIO=?, IDREGIMEN=?, VALOR=?, PERIODOPAGO=?, MESPAGO=?, FECHAINSCRIPCION=?, IDUSUARIO=?, FECHA=?, ACTIVO=?, IDMUNICIPIO=?  where  IDCOMERCIO ='"+regimencomercios.getIDCOMERCIO()+"' and  IDREGIMEN ='"+regimencomercios.getIDREGIMEN()+"' and  ACTIVO ='"+regimencomercios.getACTIVO()+"' and  IDMUNICIPIO ='"+regimencomercios.getIDMUNICIPIO()+"'  ";
      pupdate= con.prepareStatement(sql);
      pupdate.setString(1,regimencomercios.getIDCOMERCIO());
pupdate.setString(2,regimencomercios.getIDREGIMEN());
pupdate.setDouble(3,regimencomercios.getVALOR());
pupdate.setString(4,regimencomercios.getPERIODOPAGO());
pupdate.setString(5,regimencomercios.getMESPAGO());
pupdate.setDate(6,regimencomercios.getFECHAINSCRIPCION());
pupdate.setString(7,regimencomercios.getIDUSUARIO());
pupdate.setDate(8,regimencomercios.getFECHA());
pupdate.setString(9,regimencomercios.getACTIVO());
pupdate.setString(10,regimencomercios.getIDMUNICIPIO());
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* update()
*/

public static boolean update(String sqlupdate ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update  regimencomercios set " + sqlupdate +"";
      pupdate= con.prepareStatement(sql);
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* updatePrimaryKey()
*/

public static boolean updatePrimaryKey(Regimencomercios regimencomercios_old , Regimencomercios regimencomercios) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update regimencomercios set  IDCOMERCIO=? ,  IDREGIMEN=? ,  ACTIVO=? ,  IDMUNICIPIO=?  where  IDCOMERCIO ='"+regimencomercios_old.getIDCOMERCIO()+"' and  IDREGIMEN ='"+regimencomercios_old.getIDREGIMEN()+"' and  ACTIVO ='"+regimencomercios_old.getACTIVO()+"' and  IDMUNICIPIO ='"+regimencomercios_old.getIDMUNICIPIO()+"'  ";
      pupdate= con.prepareStatement(sql);
      pupdate.setString(1,regimencomercios.getIDCOMERCIO());pupdate.setString(2,regimencomercios.getIDREGIMEN());pupdate.setString(9,regimencomercios.getACTIVO());pupdate.setString(10,regimencomercios.getIDMUNICIPIO());
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* delete()
*/

public static boolean delete(Regimencomercios regimencomercios ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from regimencomercios  where  IDCOMERCIO = ? and  IDREGIMEN = ? and  ACTIVO = ? and  IDMUNICIPIO = ?  ";
      pdelete= con.prepareStatement(sql);
      pdelete.setString(1,regimencomercios.getIDCOMERCIO());
pdelete.setString(2,regimencomercios.getIDREGIMEN());
pdelete.setString(9,regimencomercios.getACTIVO());
pdelete.setString(10,regimencomercios.getIDMUNICIPIO());
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodelete"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* delete()
*/

public static boolean delete(String sqldelete ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from regimencomercios where " + sqldelete +"";
      pdelete= con.prepareStatement(sql);
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodelete"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* deleteAll()
*/

public static boolean deleteAll() {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from regimencomercios  ";
      pdelete= con.prepareStatement(sql);
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodeleteall"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* exists()
*/



public static boolean exists(Regimencomercios regimencomercios) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      String sql = "select * from regimencomercios where IDCOMERCIO='"+regimencomercios.getIDCOMERCIO()+"' and IDREGIMEN='"+regimencomercios.getIDREGIMEN()+"' and ACTIVO='"+regimencomercios.getACTIVO()+"' and IDMUNICIPIO='"+regimencomercios.getIDMUNICIPIO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimencomercios" +" " + bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return false;
   }
    rs.close();
    psquery.close();
 return true;
} catch (Exception ex) {
      excepcion = ex;
}
  return false;
}


/**
*
* findByPrimaryKey()
*/



public static Regimencomercios findByPrimaryKey(Regimencomercios regimencomercios) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
      String sql = "select * from regimencomercios where IDCOMERCIO='"+regimencomercios.getIDCOMERCIO()+"' and IDREGIMEN='"+regimencomercios.getIDREGIMEN()+"' and ACTIVO='"+regimencomercios.getACTIVO()+"' and IDMUNICIPIO='"+regimencomercios.getIDMUNICIPIO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimencomercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
Regimen regimen = new Regimen();
Regimen regimen2 = new Regimen();
RegimenController regimenController = new RegimenController();
            
    regimen.setIdregimen(rs.getString("IDREGIMEN"));
            
   regimen2 =  regimenController.findByPrimaryKey(regimen);
   if (regimen2== null) {
       //no existe registro con ese codigo 
   } else {
   regimen= regimen2;
   regimencomercios.setRegimen(regimen);
     }
            regimencomercios.setIDCOMERCIO(rs.getString("IDCOMERCIO"));
regimencomercios.setIDREGIMEN(rs.getString("IDREGIMEN"));
regimencomercios.setVALOR(rs.getDouble("VALOR"));
regimencomercios.setPERIODOPAGO(rs.getString("PERIODOPAGO"));
regimencomercios.setMESPAGO(rs.getString("MESPAGO"));
regimencomercios.setFECHAINSCRIPCION(rs.getDate("FECHAINSCRIPCION"));
regimencomercios.setIDUSUARIO(rs.getString("IDUSUARIO"));
regimencomercios.setFECHA(rs.getDate("FECHA"));
regimencomercios.setACTIVO(rs.getString("ACTIVO"));
regimencomercios.setIDMUNICIPIO(rs.getString("IDMUNICIPIO"));
    }
    rs.close();
    psquery.close();
 return regimencomercios;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIDCOMERCIO()
*/

public static List<Regimencomercios> findByIDCOMERCIO(Regimencomercios regimencomercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Regimencomercios>();
      String sql = "select * from regimencomercios where IDCOMERCIO='"+regimencomercios.getIDCOMERCIO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimencomercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
Regimen regimen = new Regimen();
Regimen regimen2 = new Regimen();
RegimenController regimenController = new RegimenController();
        Regimencomercios regimencomercios2 = new Regimencomercios(
         rs.getString("IDCOMERCIO"),rs.getString("IDREGIMEN"),rs.getDouble("VALOR"),rs.getString("PERIODOPAGO"),rs.getString("MESPAGO"),rs.getDate("FECHAINSCRIPCION"),rs.getString("IDUSUARIO"),rs.getDate("FECHA"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"));
            
    regimen.setIdregimen(rs.getString("IDREGIMEN"));
            
  if(withRelation){
     regimen2 =  regimenController.findByPrimaryKey(regimen);
     if (regimen2== null) {
       //not found records 
     } else {
     regimen= regimen2;
     regimencomercios2.setRegimen(regimen);
       }
   }
       list.add(regimencomercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIDREGIMEN()
*/

public static List<Regimencomercios> findByIDREGIMEN(Regimencomercios regimencomercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Regimencomercios>();
      String sql = "select * from regimencomercios where IDREGIMEN='"+regimencomercios.getIDREGIMEN()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimencomercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
Regimen regimen = new Regimen();
Regimen regimen2 = new Regimen();
RegimenController regimenController = new RegimenController();
        Regimencomercios regimencomercios2 = new Regimencomercios(
         rs.getString("IDCOMERCIO"),rs.getString("IDREGIMEN"),rs.getDouble("VALOR"),rs.getString("PERIODOPAGO"),rs.getString("MESPAGO"),rs.getDate("FECHAINSCRIPCION"),rs.getString("IDUSUARIO"),rs.getDate("FECHA"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"));
            
    regimen.setIdregimen(rs.getString("IDREGIMEN"));
            
  if(withRelation){
     regimen2 =  regimenController.findByPrimaryKey(regimen);
     if (regimen2== null) {
       //not found records 
     } else {
     regimen= regimen2;
     regimencomercios2.setRegimen(regimen);
       }
   }
       list.add(regimencomercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByVALOR()
*/

public static List<Regimencomercios> findByVALOR(Regimencomercios regimencomercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Regimencomercios>();
      String sql = "select * from regimencomercios where VALOR='"+regimencomercios.getVALOR()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimencomercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
Regimen regimen = new Regimen();
Regimen regimen2 = new Regimen();
RegimenController regimenController = new RegimenController();
        Regimencomercios regimencomercios2 = new Regimencomercios(
         rs.getString("IDCOMERCIO"),rs.getString("IDREGIMEN"),rs.getDouble("VALOR"),rs.getString("PERIODOPAGO"),rs.getString("MESPAGO"),rs.getDate("FECHAINSCRIPCION"),rs.getString("IDUSUARIO"),rs.getDate("FECHA"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"));
            
  regimen.setIdregimen(rs.getString("IDREGIMEN"));
            
  if(withRelation){
     regimen2 =  regimenController.findByPrimaryKey(regimen);
     if (regimen2== null) {
       //not found records 
     } else {
     regimen= regimen2;
     regimencomercios2.setRegimen(regimen);
       }
   }
       list.add(regimencomercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByPERIODOPAGO()
*/

public static List<Regimencomercios> findByPERIODOPAGO(Regimencomercios regimencomercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Regimencomercios>();
      String sql = "select * from regimencomercios where PERIODOPAGO='"+regimencomercios.getPERIODOPAGO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimencomercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
Regimen regimen = new Regimen();
Regimen regimen2 = new Regimen();
RegimenController regimenController = new RegimenController();
        Regimencomercios regimencomercios2 = new Regimencomercios(
         rs.getString("IDCOMERCIO"),rs.getString("IDREGIMEN"),rs.getDouble("VALOR"),rs.getString("PERIODOPAGO"),rs.getString("MESPAGO"),rs.getDate("FECHAINSCRIPCION"),rs.getString("IDUSUARIO"),rs.getDate("FECHA"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"));
            
regimen.setIdregimen(rs.getString("IDREGIMEN"));
            
  if(withRelation){
     regimen2 =  regimenController.findByPrimaryKey(regimen);
     if (regimen2== null) {
       //not found records 
     } else {
     regimen= regimen2;
     regimencomercios2.setRegimen(regimen);
       }
   }
       list.add(regimencomercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByMESPAGO()
*/

public static List<Regimencomercios> findByMESPAGO(Regimencomercios regimencomercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Regimencomercios>();
      String sql = "select * from regimencomercios where MESPAGO='"+regimencomercios.getMESPAGO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimencomercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
Regimen regimen = new Regimen();
Regimen regimen2 = new Regimen();
RegimenController regimenController = new RegimenController();
        Regimencomercios regimencomercios2 = new Regimencomercios(
         rs.getString("IDCOMERCIO"),rs.getString("IDREGIMEN"),rs.getDouble("VALOR"),rs.getString("PERIODOPAGO"),rs.getString("MESPAGO"),rs.getDate("FECHAINSCRIPCION"),rs.getString("IDUSUARIO"),rs.getDate("FECHA"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"));
            
 regimen.setIdregimen(rs.getString("IDREGIMEN"));
            
  if(withRelation){
     regimen2 =  regimenController.findByPrimaryKey(regimen);
     if (regimen2== null) {
       //not found records 
     } else {
     regimen= regimen2;
     regimencomercios2.setRegimen(regimen);
       }
   }
       list.add(regimencomercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByFECHAINSCRIPCION()
*/

public static List<Regimencomercios> findByFECHAINSCRIPCION(Regimencomercios regimencomercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Regimencomercios>();
      String sql = "select * from regimencomercios where FECHAINSCRIPCION='"+regimencomercios.getFECHAINSCRIPCION()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimencomercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
Regimen regimen = new Regimen();
Regimen regimen2 = new Regimen();
RegimenController regimenController = new RegimenController();
        Regimencomercios regimencomercios2 = new Regimencomercios(
         rs.getString("IDCOMERCIO"),rs.getString("IDREGIMEN"),rs.getDouble("VALOR"),rs.getString("PERIODOPAGO"),rs.getString("MESPAGO"),rs.getDate("FECHAINSCRIPCION"),rs.getString("IDUSUARIO"),rs.getDate("FECHA"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"));
            
regimen.setIdregimen(rs.getString("IDREGIMEN"));
            
  if(withRelation){
     regimen2 =  regimenController.findByPrimaryKey(regimen);
     if (regimen2== null) {
       //not found records 
     } else {
     regimen= regimen2;
     regimencomercios2.setRegimen(regimen);
       }
   }
       list.add(regimencomercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIDUSUARIO()
*/

public static List<Regimencomercios> findByIDUSUARIO(Regimencomercios regimencomercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Regimencomercios>();
      String sql = "select * from regimencomercios where IDUSUARIO='"+regimencomercios.getIDUSUARIO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimencomercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
Regimen regimen = new Regimen();
Regimen regimen2 = new Regimen();
RegimenController regimenController = new RegimenController();
        Regimencomercios regimencomercios2 = new Regimencomercios(
         rs.getString("IDCOMERCIO"),rs.getString("IDREGIMEN"),rs.getDouble("VALOR"),rs.getString("PERIODOPAGO"),rs.getString("MESPAGO"),rs.getDate("FECHAINSCRIPCION"),rs.getString("IDUSUARIO"),rs.getDate("FECHA"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"));
            
regimen.setIdregimen(rs.getString("IDREGIMEN"));
            
  if(withRelation){
     regimen2 =  regimenController.findByPrimaryKey(regimen);
     if (regimen2== null) {
       //not found records 
     } else {
     regimen= regimen2;
     regimencomercios2.setRegimen(regimen);
       }
   }
       list.add(regimencomercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByFECHA()
*/

public static List<Regimencomercios> findByFECHA(Regimencomercios regimencomercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Regimencomercios>();
      String sql = "select * from regimencomercios where FECHA='"+regimencomercios.getFECHA()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimencomercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
Regimen regimen = new Regimen();
Regimen regimen2 = new Regimen();
RegimenController regimenController = new RegimenController();
        Regimencomercios regimencomercios2 = new Regimencomercios(
         rs.getString("IDCOMERCIO"),rs.getString("IDREGIMEN"),rs.getDouble("VALOR"),rs.getString("PERIODOPAGO"),rs.getString("MESPAGO"),rs.getDate("FECHAINSCRIPCION"),rs.getString("IDUSUARIO"),rs.getDate("FECHA"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"));
            
regimen.setIdregimen(rs.getString("IDREGIMEN"));
            
  if(withRelation){
     regimen2 =  regimenController.findByPrimaryKey(regimen);
     if (regimen2== null) {
       //not found records 
     } else {
     regimen= regimen2;
     regimencomercios2.setRegimen(regimen);
       }
   }
       list.add(regimencomercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByACTIVO()
*/

public static List<Regimencomercios> findByACTIVO(Regimencomercios regimencomercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Regimencomercios>();
      String sql = "select * from regimencomercios where ACTIVO='"+regimencomercios.getACTIVO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimencomercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
Regimen regimen = new Regimen();
Regimen regimen2 = new Regimen();
RegimenController regimenController = new RegimenController();
        Regimencomercios regimencomercios2 = new Regimencomercios(
         rs.getString("IDCOMERCIO"),rs.getString("IDREGIMEN"),rs.getDouble("VALOR"),rs.getString("PERIODOPAGO"),rs.getString("MESPAGO"),rs.getDate("FECHAINSCRIPCION"),rs.getString("IDUSUARIO"),rs.getDate("FECHA"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"));
            
   regimen.setIdregimen(rs.getString("IDREGIMEN"));
            
  if(withRelation){
     regimen2 =  regimenController.findByPrimaryKey(regimen);
     if (regimen2== null) {
       //not found records 
     } else {
     regimen= regimen2;
     regimencomercios2.setRegimen(regimen);
       }
   }
       list.add(regimencomercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIDMUNICIPIO()
*/

public static List<Regimencomercios> findByIDMUNICIPIO(Regimencomercios regimencomercios,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Regimencomercios>();
      String sql = "select * from regimencomercios where IDMUNICIPIO='"+regimencomercios.getIDMUNICIPIO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimencomercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
Regimen regimen = new Regimen();
Regimen regimen2 = new Regimen();
RegimenController regimenController = new RegimenController();
        Regimencomercios regimencomercios2 = new Regimencomercios(
         rs.getString("IDCOMERCIO"),rs.getString("IDREGIMEN"),rs.getDouble("VALOR"),rs.getString("PERIODOPAGO"),rs.getString("MESPAGO"),rs.getDate("FECHAINSCRIPCION"),rs.getString("IDUSUARIO"),rs.getDate("FECHA"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"));
            
    regimen.setIdregimen(rs.getString("IDREGIMEN"));
            
  if(withRelation){
     regimen2 =  regimenController.findByPrimaryKey(regimen);
     if (regimen2== null) {
       //not found records 
     } else {
     regimen= regimen2;
     regimencomercios2.setRegimen(regimen);
       }
   }
       list.add(regimencomercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* locateByParameters()
*/

public static List<Regimencomercios> locateByParameters(Map parametros,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Regimencomercios>();
  String sql = "select * from regimencomercios";
  if (parametros != null) {
      Iterator it = parametros.entrySet().iterator();
      StringBuilder sb = new StringBuilder("");
      int i = 0;
      while (it.hasNext()) {
          if (i != 0){
            sb.append(" and ");
         }
         i++;
        Map.Entry e = (Map.Entry) it.next();
        sb.append(e.getKey() +"= '"+  e.getValue()+"'");
      }
      if (!sb.toString().equals("")){
         sql = sql + " where " + sb.toString();
      }
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimencomercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
Regimen regimen = new Regimen();
Regimen regimen2 = new Regimen();
RegimenController regimenController = new RegimenController();
        Regimencomercios regimencomercios2 = new Regimencomercios(
         rs.getString("IDCOMERCIO"),rs.getString("IDREGIMEN"),rs.getDouble("VALOR"),rs.getString("PERIODOPAGO"),rs.getString("MESPAGO"),rs.getDate("FECHAINSCRIPCION"),rs.getString("IDUSUARIO"),rs.getDate("FECHA"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"));
            
   regimen.setIdregimen(rs.getString("IDREGIMEN"));
            
  if(withRelation){
     regimen2 =  regimenController.findByPrimaryKey(regimen);
     if (regimen2== null) {
       //not found records 
     } else {
     regimen= regimen2;
     regimencomercios2.setRegimen(regimen);
       }
   }
       list.add(regimencomercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* Double fFunc(String funcion, String campo)
*/



public static Double func(String funcion, String campo) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0.0;
  }
      String sql = "select "+funcion+"("+campo+") as contador from regimencomercios";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimencomercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0.0;
   }
    Double tmp =0.0;
   rs.beforeFirst();
   while (rs.next()) {
    tmp =  rs.getDouble("contador");
    }
    rs.close();
    psquery.close();
 return tmp;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0.0;
}


/**
*
* Double func(String funcion, String campo,String where)
*/



public static Double func(String funcion, String campo, String where) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0.0;
  }
      String sql = "select "+funcion+"("+campo+") as contador from regimencomercios where "+where +" ";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimencomercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0.0;
   }
    Double tmp =0.0;
   rs.beforeFirst();
   while (rs.next()) {
    tmp =  rs.getDouble("contador");
    }
    rs.close();
    psquery.close();
 return tmp;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0.0;
}


/**
*
* count()
*/



public static Integer count() {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0;
  }
      String sql = "select count(*) as contador from regimencomercios";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimencomercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0;
   }
   rs.beforeFirst();
   while (rs.next()) {
    x =  rs.getInt("contador");
    }
    rs.close();
    psquery.close();
 return x;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0;
}


/**
*
* count(String sqlquery)
*/



public static Integer count(String sqlquery) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0;
  }
      String sql = "select count(*) as contador from regimencomercios where  " + sqlquery +"";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimencomercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0;
   }
   rs.beforeFirst();
   while (rs.next()) {
    x =  rs.getInt("contador");
    }
    rs.close();
    psquery.close();
 return x;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0;
}


/**
*
* query()
*/

public static List<Regimencomercios> query(String query,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
        list = new ArrayList<Regimencomercios>();
  String sql = "select * from regimencomercios where " + query +"";
  if (query == null || query.equals("")) {
  return null;
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimencomercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
Regimen regimen = new Regimen();
Regimen regimen2 = new Regimen();
RegimenController regimenController = new RegimenController();
        Regimencomercios regimencomercios2 = new Regimencomercios(
         rs.getString("IDCOMERCIO"),rs.getString("IDREGIMEN"),rs.getDouble("VALOR"),rs.getString("PERIODOPAGO"),rs.getString("MESPAGO"),rs.getDate("FECHAINSCRIPCION"),rs.getString("IDUSUARIO"),rs.getDate("FECHA"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"));
            
regimen.setIdregimen(rs.getString("IDREGIMEN"));
            
  if(withRelation){
     regimen2 =  regimenController.findByPrimaryKey(regimen);
     if (regimen2== null) {
       //not found records 
     } else {
     regimen= regimen2;
     regimencomercios2.setRegimen(regimen);
       }
   }
       list.add(regimencomercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* getListRecords()
*/

public static List<Regimencomercios> getListRecords(Map parametros,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
      list = new ArrayList<Regimencomercios>();
  String sql = "select * from regimencomercios";
  if (parametros != null) {
      Iterator it = parametros.entrySet().iterator();
      StringBuilder sb = new StringBuilder("");
      while (it.hasNext()) {
        Map.Entry e = (Map.Entry) it.next();
        sb.append(e.getKey() +"="+  e.getValue());
      }
      if (!sb.toString().equals("")){
         sql = sql + " where " + sb.toString();
      }
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "regimencomercios" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
       
Regimen regimen = new Regimen();
Regimen regimen2 = new Regimen();
RegimenController regimenController = new RegimenController();
        Regimencomercios regimencomercios2 = new Regimencomercios(
         rs.getString("IDCOMERCIO"),rs.getString("IDREGIMEN"),rs.getDouble("VALOR"),rs.getString("PERIODOPAGO"),rs.getString("MESPAGO"),rs.getDate("FECHAINSCRIPCION"),rs.getString("IDUSUARIO"),rs.getDate("FECHA"),rs.getString("ACTIVO"),rs.getString("IDMUNICIPIO"));
            
 regimen.setIdregimen(rs.getString("IDREGIMEN"));
            
  if(withRelation){
     regimen2 =  regimenController.findByPrimaryKey(regimen);
     if (regimen2== null) {
       //not found records 
     } else {
     regimen= regimen2;
     regimencomercios2.setRegimen(regimen);
       }
   }
       list.add(regimencomercios2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
 }


}
